<template>
	<view>
		<view class="section-head">
			<view class="u-p-30">
				<view class="blue-text"></view>
				<text class="u-font-32">用户信息</text>
			</view>
		</view>
		<!-- 小哥 -->
		<template v-if="type == '4'">
			<view class="user-msg u-flex u-border-bottom">
				<view class="u-w-240 u-text-center">
					<u-avatar :src="fileURL+info.face" :size="150"></u-avatar>
				</view>
				<view class="list u-flex-1">
					<view class="item">用户类型：{{info.usertype}}</view>
					<view class="item">用户昵称：{{info.name}}</view>
					<view class="item" v-if="info.ysid">猿收ID：{{info.ysid}}</view>
					<view class="item">电话：{{info.mobile}}</view>
				</view>
			</view>
			<view class="section-head">
				<view class="u-p-30">
					<view class="blue-text"></view>
					<text class="u-font-32">订单信息</text>
				</view>
			</view>
			<u-cell-group>
				<u-cell-item hover-class="none" :arrow="false" v-for="(item,index) in brotherOrderData" :key="index">
					<view slot="title"><text class="color-danger">{{item.state}}</text></view>
					<view slot="label">订单编号：{{item.number}}</view>
					<view slot="right-icon">
						<u-button v-if="item.state == '待入库'" @click="brotherOrderDetails(item)" type="primary" size="medium">入库录入</u-button>
						<u-button v-else-if="item.state == '已装车'" @click="brotherOrderDetails(item)" type="primary" size="medium">出库复核</u-button>
						<u-button v-else @click="brotherOrderDetails(item)" type="primary" size="medium" plain>立即查看</u-button>
					</view>
				</u-cell-item>
			</u-cell-group>
			<view class="u-p-t-30">
				<u-loadmore :status="loadStatus"></u-loadmore>
			</view>
		</template>
		<!-- 个人用户 -->
		<template v-else>
			<view class="user-msg u-flex u-border-bottom">
				<view class="u-w-240 u-text-center">
					<u-avatar :src="fileURL+info.face" :size="150"></u-avatar>
				</view>
				<view class="list u-flex-1">
					<view class="item">用户类型：{{info.usertype}}</view>
					<view class="item">用户昵称：{{info.name}}</view>
					<view class="item">猿收ID：{{info.ysid}}</view>
					<view class="item">电话：{{info.mobile}}</view>
				</view>
			</view>
			<view class="u-p-30">
				<text class="u-tips-color">确定用户后，进行入库录入</text>
				<view class="u-p-t-80">
					<view class="u-flex">
						<u-button plain class="u-flex-1 u-m-r-15" @click="back">返回扫码</u-button>
						<u-button type="primary" class="u-flex-1 u-m-l-15" @click="income">立即录入</u-button>
					</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: null,//type为4时表示小哥
				relationid: null,
				info:{
					face: ''
				},
				brotherOrderData: [],
				PageIndex: 1,
				PageSize: 20,
				key: '',
				noMore: false,
				loadStatus: 'loading',
				// isschool: false, //判断是否为学校
				// userType: null, //用户类型
				uidOrEid: null, //个人或客户组id
			}
		},
		onLoad(opt) {
			this.message = opt.message
			// this.isschool = opt.isschool
			this.getQRCodeData()
		},
		onReachBottom(e){
			this.reachBottom()
		},
		onPullDownRefresh() {
			this.PageIndex = 1
			this.brotherOrderData = []
			this.getBrotherOrderData().then(()=>{
				uni.stopPullDownRefresh(); //停止当前页面下拉刷新
			})
		},
		methods: {
			// 查看小哥订单详情
			brotherOrderDetails(item){
				if(item.type == 0){
					uni.navigateTo({
						url: '../../income/views/views?id='+item.orderid
					})
				}else {
					uni.navigateTo({
						url: '../../outbound/views/views?id='+item.orderid
					})
				}
			},
			income(){
				uni.navigateTo({
					url: '../../income/user/create/create?id='+this.uidOrEid+'&type='+this.type+'&message='+this.message
				})
			},
			back(){
				uni.navigateBack()
			},
			getQRCodeData(){
				// 二维码的格式为aa-bb-cc，aa表示类型：2为个人3为客户组，bb表示个人或客户组id
				// let codeArr = this.message.split('-')
				// this.userType = codeArr[0]
				// this.uidOrEid = codeArr[1] //个人或客户组id
				return this.$u.get('/AIO/Account/GetQRCodeInfo?code='+this.message).then((res)=>{
					console.log('getQRCodeData2:',res)
					this.info = res.data
					this.uidOrEid = res.data.userid || res.data.enterpriseid
					this.type = res.type
					if(res.type == 4){
						this.getBrotherOrderData()
					}
				})
			},
			getBrotherOrderData(){
				return this.$u.post('/Store/BrotherOrder/Undone',{
					"PageIndex": this.PageIndex,
					"PageSize": this.PageSize,
					"key": this.key,
					"BrotherId": this.info.brotherid
				}).then((res)=>{
					console.log('getQRCodeData:',res)
					// this.brotherOrderData = res
					
					let datas = res.rows
					if (datas.length > 0) {
						datas.forEach((item) => {
							this.brotherOrderData.push(item)
						})
						if (datas.length < this.PageSize) {
							this.loadStatus = "nomore"
						} else {
							this.loadStatus = "loadmore"
						}
					} else {
						this.loadStatus = "nomore"
					}
				})
			},
			reachBottom() {
				// 此tab为空数据
				this.PageIndex += 1
				this.getBrotherOrderData()
			},
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fff;
	}
	.user-msg{
		padding-bottom: 30rpx;
		.list{
			.item{
				font-size: 28rpx;
				margin-bottom: 4rpx;
			}
		}
	}
</style>
